import * as Cesium from "cesium";
interface IAddBoxParams {
  coordinates: Cesium.Cartesian3[];
  height: number;
  identifier: string;
  viewer: Cesium.Viewer;
  show?: boolean;
  alpha?: number;
}

const addBox = (params: IAddBoxParams): Cesium.Entity => {
  const coordinates = params.coordinates;
  const height = params.height;
  const viewer = params.viewer;
  const identifier = params.identifier;
  const show = false || params.show;
  const alpha = params.alpha ? params.alpha : 0.5;

  const entity = new Cesium.Entity({
    id: identifier,
    name: "building",
    polygon: new Cesium.PolygonGraphics({
      hierarchy: new Cesium.PolygonHierarchy(coordinates),
      extrudedHeight: height,
      extrudedHeightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
      fill: true,
      material: !show
        ? new Cesium.Color(1.0, 1.0, 1.0, 0.01)
        : new Cesium.Color(1.0, 1.0, 1.0, alpha),
    }),
  });
  viewer.entities.add(entity);
  return entity;
};

export default addBox;
